import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import './course_detail.less'
import TopNav from '../../top_nav'
import DetailBanner from './detail_banner'
import DetailContent from './detail_content'
import courseApi from '../../../api/course'
import parseUrl from '../../../utils/parseUrl'
class CourseDetail extends Component {
  state={
    courseId:"",
    courseInfo:{}
  }
  componentDidMount() {
    window.scrollTo(0, 0);
    this.getCourseDetails()
  }
  getCourseDetails = ()=>{
    courseApi.getDetails(parseUrl(this.props.location.search).courseId).then(res=>{
      if(res.success){
        this.setState({
          courseInfo:res.data.course
        })
      }
    }).catch(err=>{
      console.log(err);
    })
  }
  render() {
    const {courseInfo} = this.state
    return (
      <div className="course-detail-container">
        <TopNav style={{ background: '#fff' }} active="/course" />
        <DetailBanner {...courseInfo}/>
        <DetailContent {...courseInfo}/>
      </div>
    )
  }
}
export default withRouter(CourseDetail)